package com.sudo.boot.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Demo2 {

    /**
     * FileChannel 写数据
     */
    public static void main(String[] args) throws IOException {
        RandomAccessFile raf = new RandomAccessFile("D:\\code-space\\java\\io-demo\\src\\main\\resources\\2.txt", "rw");
        FileChannel channel = raf.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(10);

        String data = "12345678901";
        buffer.put(data.getBytes());
        buffer.flip();
        channel.write(buffer);
        buffer.clear();
        channel.close();
    }
}
